import { useCallback } from "react";
import { useDispatch } from "react-redux";
import actions from "../store/actions";
import api from "./index";

function useGetTopics() {
    const dispatch = useDispatch();

    return useCallback((page, tab) => {
        dispatch({
            type: actions.topics.loading,
        });

        api.topics(page, tab).then((res) => {
            dispatch({
                type: actions.topics.update,
                data: res.data.data,
            });
        });
    }, []);
}

export { useGetTopics };
